package com.uu;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.opengl.GLES11Ext;
import android.opengl.GLES20;
import android.os.Bundle;
import android.os.Environment;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageView;

import com.cv.OpencvJni;
import com.cv.util.CameraHelper;
import com.cv.util.Utils;
import com.opengllib.TestActivity;

import java.io.File;

import javax.microedition.khronos.opengles.GL10;

public class MainActivity extends AppCompatActivity {


    private ImageView imageView;
    private Bitmap bitmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                next();
            }
        });

        findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gray();
            }
        });

        imageView = (ImageView)findViewById(R.id.image);
        bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.d);
        imageView.setImageBitmap(bitmap);
        Utils.copyAssets(this, "lbpcascade_frontalface.xml");
    }

    public void showImage(){
        bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.d);
        imageView.setImageBitmap(bitmap);
    }

    private void next(){
        startActivity(new Intent(this, TestActivity.class));
    }
    public void gray(){
        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        int[] piexls = new int[w*h];
        bitmap.getPixels(piexls,0,w,0,0,w,h);
        int[] resultData =OpencvJni.Bitmap2Grey(piexls,w,h);
        Bitmap resultImage = Bitmap.createBitmap(w,h, Bitmap.Config.ARGB_8888);
        resultImage.setPixels(resultData,0,w,0,0,w,h);
        imageView.setImageBitmap(resultImage);
    }

}
